﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Diagnostics;

namespace Model
{
    public partial class CodeForm : Form
    {
        public CodeForm()
        {
            InitializeComponent();
            Form.CheckForIllegalCrossThreadCalls = false;
        }

        public void Show(string imgUrl)
        {
            WebClient client = new WebClient();
            var datas = client.DownloadData(imgUrl);
            MemoryStream stream = new MemoryStream(datas);
            Image image = Image.FromStream(stream);
            this.pictureBox1.Image = image;
            this.ShowDialog(new Win32Window());
        }

        public void Show(Image image)
        {
            this.pictureBox1.Image = image;
            this.ShowDialog(new Win32Window());
        }

        public string Code { get { return this.textBox1.Text; } }

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.textBox1.Text.Length > 0) { this.Close(); }
        }

        private void CodeForm_Load(object sender, EventArgs e)
        {
            this.textBox1.Focus();
        }

        private class Win32Window : IWin32Window
        {

            public IntPtr Handle
            {
                get { return Process.GetCurrentProcess().MainWindowHandle; }
            }
        }
    }
}
